package org.rain.core;

import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.rain.common.enums.RespCode;
import org.rain.common.model.R;
import org.springframework.core.annotation.AliasFor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.lang.annotation.*;

/**
 * created by yangtong on 2025/4/13 16:37:24
 * <br/>
 * 用来标注文件下载接口
 */
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@RequestMapping(method = RequestMethod.GET)
@ApiResponses({
        @ApiResponse(
                responseCode = "0",
                description = "文件下载成功",
                content = @Content(
                        mediaType = "application/octet-stream",
                        schema = @Schema(type = "string", format = "binary")
                )
        ),
        @ApiResponse(
                responseCode = "405",
                description = "下载失败，返回 JSON 错误信息",
                content = @Content(
                        mediaType = "application/json",
                        schema = @Schema(implementation = R.class)
                )
        )
})
public @interface DownloadMapper {
    /**
     * 路径映射，对应 @GetMapping.value
     */
    @AliasFor(annotation = RequestMapping.class, attribute = "value")
    String[] value() default {};

    /**
     * 可选：支持自定义 produces（覆盖默认值）
     */
    @AliasFor(annotation = RequestMapping.class, attribute = "produces")
    String[] produces() default {MediaType.APPLICATION_OCTET_STREAM_VALUE};
}
